var storyDAO = require('../models/storyDAO')
var fomidable = require('formidable')
var path = require('path')
var storyController = {
    getALLStory:function(req,res){
        storyDAO.getALLStory(function(err,results){
            if(err){
                res.json({code:500,msg:'查询失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'查询成功'})
            }
        })

    },
    getStoryId : function(req,res){
        var storysID = req.query.storysID
        storyDAO.getStoryId(storysID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'查询失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'查询成功'})
            }
        })
    },
    getbackStoryId : function(req,res){
        var storysID = req.query.storysID
        storyDAO.getbackStoryId(storysID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'查询失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'查询成功'})
            }
        })
    },
    insertStory : function(req,res){
        var userId = req.body.userId
        var content = req.body.content
      storyDAO.insertStory({userId:userId,content:content},function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'上传失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'上传成功'})
            }
        })
    },
    insertBackStory: function(req,res){
        // console.log('ce')
        var storyreplycontent = req.body.storyreplycontent
        var userId= req.body.userId
        var storysID = req.body.storysID
        storyDAO.insertBackStory({storyreplycontent:storyreplycontent,userId:userId,storysID:storysID},function(err,results){
            if(err){
                // console.log(err)
                res.json({code:500,msg:'上传失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'上传成功'})
            }
        })
    },
    delBackStory: function(req,res){
        var storyreplyID = req.query.storyreplyID
      storyDAO.delBackStory(storyreplyID,function(err,results){
            if(err){
                console.log(err)
                res.json({code:500,msg:'删除失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'删除成功'})
            }
        })
    },
    delStory: function(req,res){
        var storysID = req.query.storysID
      storyDAO.delStory(storysID,function(err,results){
        console.log('测试')
            if(err){
                console.log(err)
                res.json({code:500,msg:'删除失败'})
            }
            else{
                console.log(results)
                res.json({code:200,data:results,msg:'删除成功'})
            }
        })
    },
    

}
module.exports = storyController